package Acwing;

public class Acwing15 {
    public static boolean searchArray(int[][] array, int target) {
          int i=0;
          int j=0;
          boolean output=true;
          while(true){
              if(i<0||j<0||i==array.length){
                  output=false;
                  break;
              }
              if(j==array[0].length){
                  j=0;
                  i++;
                  continue;
              }
              if(array[i][j]==target){
                  output=true;
                  break;
              }
              if(array[i][j]<target){
                  j++;
              }else if(array[i][j]>target){
                  i++;
                  j=0;
              }
          }
          return output;
    }

    public static void main(String[] args) {
        int[][] arr={{1,2,8,9},{2,4,9,12},{4,7,10,13},{6,8,11,15}};
        System.out.println(searchArray(arr,1231));
    }
}
